package cn.ywang.pattern.prototype.deep;

import cn.ywang.pattern.prototype.model.TestCase;

import java.io.*;

/**
 * 深拷贝
 *
 * @author BeatificWang
 * @date 2019/3/11 22:44
 */
public class DeepTestCase extends TestCase implements Cloneable, Serializable {


	@Override
	protected DeepTestCase clone() throws CloneNotSupportedException {
		DeepTestCase deepTestCase = null;
		try {
			//序列化
			ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
			ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
			objectOutputStream.writeObject(this);
			// 反序列化
			ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
			ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
			deepTestCase = (DeepTestCase) objectInputStream.readObject();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return deepTestCase;
	}
}
